package IC.lir.Instrunction;

public class FieldMemory extends Memory {

	private Register _obj;
	private int _fieldOfSet;
	
	public FieldMemory(Register obj, int fieldOfSet)
	{
		_obj = obj;
		_fieldOfSet = fieldOfSet; 
	}
	
	public String toString()
	{
		return String.format("%s.%d", _obj.toString(), _fieldOfSet);
	}
	public Instruction Load(int regNum) { return Load(null); }
	public Instruction Load(Register toWhere)
	{ 
		return new FieldAccessInstruction(this, toWhere == null ? _obj : GetStoreRegister(0)); 
	}	
	
	public Register GetStoreRegister(int regNum) { return new Register(_obj.GetIndex()); }
	
	public Instruction Store(Storable what) { return new FieldStoreInstruction(this, what); }
	
	public int GetNumOfRegisters() { return 1; }
}
